﻿using System.ComponentModel.DataAnnotations;

namespace NETCORE.TAttribute.Valide
{
    public class CanToIntAttribute : ValidationAttribute
    {
        /// <summary>
        /// IsValid 为 false 时，提示得 error 信息
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            return $"{name} need to int";
        }

        /// <summary>
        /// 验证当前字段得结果
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool IsValid(object value)
        {
            int num = 0;
            return int.TryParse(Convert.ToString(value), out num);
        }
    }
}
